<?php
if (! defined ( 'BASEPATH' )) {
	exit ( 'No direct script access allowed' );
}

/*
 *用户主页
 *@author 湾湾
 */
class user_home extends MY_Controller {
	function __construct() {
		parent::__construct ();
		$this->load->library ( "code_home" );
	}
	
	function index($userId='') {
		
			$this->load->model ( "user_model" );
			$state	 			= $this->checkState ( $userId );
			$userInfo			= $this->user_model->queryOneUserInfo ( array ("perserteeId" => $userId ) );
			$array ['topDiv'] 	= $this->code_home->topDiv ( $state );
			$array ['userId'] 	= $userId;
			$array				= array_merge ( $array, $this->code_home->leftDiv ( $userInfo, $state ) );
			$this->getHeader ();
			$this->load->view ( "home/main", $array );
			$this->load->view ( "footers/footer01" );
		
	}
	function showData($userId, $beginNumber = 1, $pageSize = 5, $type = '', $ownerType = 1, $teamId = '', $id = 0) {
		$array=$this->getShowPageToUser ( $userId, $type, $id,$beginNumber,$pageSize );
		log_message("info","log right info".json_encode($array));
		$this->load->view ( "home/right",$array);
	}
	/**
	 * Enter description here ...
	 * @param userId
	 * @param type
	 * @param id
	 */
	 function getShowPageToUser($userId, $type, $id=0, $beginNumber = 1, $pageSize = 5,$more=0) {
		$state = $this->checkState ( $userId );
		$divCode = "";
		$type=($type=='')?'dynamic':$type;
		$array = array ();
		$array ["userId"] = $userId;
		$array ["deleFlag"] = 0;
		if ($id != 0) {
			$array ["id"] = $id;
		}
		$table = 'wanwan_enum_userdynamic';
		$dynamic = '';
		switch ($type) {
			case 'yearbook' :
				$table = 'wanwan_enum_yearbook';
				$this->load->model ( "yearbook_model" );
				$data = $this->yearbook_model->queryPersonalYearbook ( $array, $beginNumber, $pageSize );
				$divCode = $this->getHomeDynamicDiv ( $data, $state, $type );
				break;
			case 'photowall' :
				$table = 'wanwan_enum_photowall';
				$this->load->model ( "photowall_model" );
				$array = $this->photowall_model->queryPersonalYearbook ( $array, $beginNumber, $pageSize );
				$data ['personal'] ['result'] = json_encode ( $array );
				$data ['personal'] ['description'] = "个人图片";
				$divCode = $this->getHomeDynamicDiv ( $data, $state, $type );
				break;
			case 'team' :
				$table = 'wanwan_enum_usertoteam';
				$this->load->model ( 'user_model' );
				$data = $this->user_model->getTeamInfoAll ( $array, $beginNumber, $pageSize );
				$divCode = $this->getHomeDynamicDiv ( $data, $state, $type );
				break;
			case 'friendList':
				$table ='wanwan_enum_usertouser';
				$divCode .=$this->getFriendsList ( $userId );
				break;
			default :
				$this->load->model ( "user_dynamic/user_dynamic_model" );
				$data = $this->user_dynamic_model->queryUserDynamicData ( $userId, $type, $beginNumber, $pageSize, $id );
				$divCode = $this->code_home->homeDynamicDiv ( $data, $state, $id );
				$controller = base_url ( "index.php/team/replayUsersDynamic" );
				$baseUrl = base_url ( "index.php" );
				$reload = $this->getPara ( $userId, $type, $id );
				$dynamic = "$('#contentDynamicData').wjSubmit({toggle:'div_display_',attr:'replyId',parameters:['reply_content','dynamicId'],type:'$type',baseUrl:'$baseUrl',eventClass:'send_btn',reload:'$reload',url:'$controller'});";
				$dynamic .= "$('#contentDynamicData').wjReplay({eventClass:'dynamic_reply',toggle:'div_display_'});";
				break;
		} 
		if($more==1) {
			echo $divCode;
			return ;
		}
		$jsCode = $this->getHomeJS ( $userId, $type, $table, $dynamic, $id );
		$moreCode=$this->getMoreDiv($beginNumber, $pageSize);
		return array("divCode"=>$jsCode.$divCode,"moreCode"=>$moreCode);
	}
	
	
	private function  getMoreDiv($beginNumber,$pageSize){
		return "<div class='moreFoot_wj'><a style='cursor:pointer' beginNumber='$beginNumber' pageSize='$pageSize' class='showMore'>更多&lt;&lt;&lt; </a></div>";
		
	}
	/**
	 * Enter description here ...
	 * @param userId
	 * @param type
	 * @param table
	 */
	private function getHomeJS($userId, $type, $table, $dynamic, $id) {
		//$userId, $type, $id=0, $beginNumber = 1, $pageSize = 5,$more=0
		
		$baseUrl 		= base_url ( 'index.php/' );
		$para			= $this->getPara ( $userId, $type, $id );
		$controller 	= base_url ( "index.php/public_view/delePersonalInfo/$table" );
		$showMore		=base_url("index.php/user_home/getShowPageToUser/$userId/$type/$id");
		$postUrl		= base_url ( "index.php/user_home/jqueryPost" );
		$jsCode 		= "<script type='text/javascript'>";
		$jsCode 		.= "$(document).ready(function () {";
		$jsCode 		.= "$('#contentDynamicData').wjViewDetail({attr:'deleId',loadDiv:'contentDynamicData',url:'$postUrl',eventClass:'viewDetail'});";
		$jsCode 		.= "$('#contentDynamicData').wjShowMore({page:'page',pageSize:'pageSize',loadDiv:'contentDynamicData',controller:'$showMore',eventClass:'showMore'});";
		$jsCode 		.= "$('#contentDynamicData').wjmoreClick({attr:'deleId',parameters:{},type:'$type',baseUrl:'$baseUrl',eventClass:'eventClass',reloadModel:'$para',url:'$controller'});";
		$jsCode 		.= $dynamic;
		$jsCode .= "});";
		$jsCode .= "</script>";
		return $jsCode;
	}
	/**
	 * Enter description here ...
	 * @param userId
	 * @param type
	 * @param id
	 */
	private function getPara($userId, $type, $id) {
		$para = base_url ( "index.php/user_home/showData/$userId/1/5/$type/1/-1/$id" );
		return $para;
	}
	
	function jqueryPost() {
		echo 'success';
	}

	function friendListPage($userId,$id=0) {
		$this->getHeader ();
		//getShowPageToUser($userId, $type, $id, $beginNumber = 1, $pageSize = 5) 
		$array=$this->getShowPageToUser ( $userId, 'friendList',$id,-1);
		$this->load->view ( "friends_list/main",$array );
		$this->load->view ( "footers/footer01" );
	}

}
?>